﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace ZEFIT
{
    class MYSQLAdabterProject : Adabter
    {
        public override List<object> Select()
        {
            String conString = "SELECT ag.ID, ag.Name, ag.Deadline, ag.Status, ku.ID, ku.Name FROM tbl_projekt as ag, tbl_kunde as ku WHERE ag.Kunde_ID = ku.ID;";
            List<object> reader = MYSQLConnecter.SelectRows(new MySqlCommand(conString));
            return reader;
        }

        public override void Insert(ref Data data)
        {
            Project project = (Project)data;
            String conString = "INSERT INTO tbl_projekt (Name, Deadline, Status, Kunde_ID) VALUES" +
                " ('" + project.Name + "', '" + project.DeadLine.ToString("yyyy-MM-dd HH:mm:ss") + "', '" + project.Status + "', " + project.Customer.Id + ");";
            project.Id = MYSQLConnecter.SendInsert(new MySqlCommand(conString));

        }

        public override void Update(Data data)
        {
            Project project = (Project)data;

            String conString = "UPDATE tbl_projekt" +
                " SET Name = '" + project.Name + "', Deadline = '" + project.DeadLine.ToString("yyyy-MM-dd HH:mm:ss") + "', Status = '" + project.Status + "', Kunde_ID = " + project.Customer.Id + 
                " WHERE ID = " + project.Id + ";";
            MYSQLConnecter.Send(new MySqlCommand(conString));
        }

        public override void Delete(int id)
        {
            String conString = "DELETE FROM tbl_projekt" +
                " WHERE ID = " + id + ";";
            MYSQLConnecter.Send(new MySqlCommand(conString));
        }
    }
}
